package cn.bs.busuo.account.controller;

import cn.bs.busuo.account.pojo.vo.*;
import cn.bs.busuo.account.service.IFavoriteService;
import cn.bs.busuo.account.service.ITagService;
import cn.bs.busuo.common.pojo.authentication.CurrentPrincipal;
import cn.bs.busuo.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/users/favorite")
@Api(tags = "4.管理员收藏接口")
public class FavoriteController {
    @Autowired
    private IFavoriteService favoriteService;

    /**
     * 添加酒店收藏
     */
    @GetMapping("/{hotelId:[0-9]+}/hotel/add")
    @PreAuthorize("hasAuthority('/account/user/system')")
    @ApiOperation("添加酒店收藏")
    @ApiOperationSupport(order = 500)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hotelId", value = "酒店ID", required = true, dataType = "long")
    })
    public JsonResult addFavoriteHotel(@PathVariable @Range(min = 1, message = "请提交合法的酒店ID值！")Long hotelId,
                                       @ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        favoriteService.addFavoriteHotel(hotelId,principal.getId());
        return JsonResult.ok();
    }

    /**
     * 查询酒店收藏(自己)
     */
    @GetMapping("/hotel/select")
    @PreAuthorize("hasAuthority('/account/user/system')")
    @ApiOperation("查询酒店收藏")
    @ApiOperationSupport(order = 510)
    public JsonResult selectFavoriteHotel(@ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        List<FavoriteHotelVO> favoriteHotelVOS= favoriteService.selectFavoriteHotel(principal.getId());
        return JsonResult.ok(favoriteHotelVOS);
    }

    /**
     * 删除酒店收藏
     */
    @GetMapping("/{hotelId:[0-9]+}/hotel/delete")
    @PreAuthorize("hasAuthority('/account/user/system')")
    @ApiOperation("删除酒店收藏")
    @ApiOperationSupport(order = 520)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hotelId", value = "酒店ID", required = true, dataType = "long")
    })
    public JsonResult deleteFavoriteHotel(@PathVariable @Range(min = 1, message = "请提交合法的酒店ID值！")Long hotelId,
                                          @ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        favoriteService.deleteFavoriteHotel(hotelId,principal.getId());
        return JsonResult.ok();
    }

    /**
     * 添加景点收藏
     */
    @GetMapping("/{sightId:[0-9]+}/sight/add")
    @PreAuthorize("hasAuthority('/account/user/system')")
    @ApiOperation("添加景点收藏")
    @ApiOperationSupport(order = 530)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sightId", value = "景点ID", required = true, dataType = "long")
    })
    public JsonResult addFavoriteSight(@PathVariable @Range(min = 1, message = "请提交合法的景点ID值！")Long sightId,
                                       @ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        favoriteService.addFavoriteSight(sightId,principal.getId());
        return JsonResult.ok();
    }

    /**
     * 查询景点收藏(自己)
     */
    @GetMapping("/sight/select")
    @PreAuthorize("hasAuthority('/account/user/system')")
    @ApiOperation("查询景点收藏")
    @ApiOperationSupport(order = 540)
    public JsonResult selectFavoriteSight(@ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        List<FavoriteSightVO> favoriteSightVOS= favoriteService.selectFavoriteSight(principal.getId());
        return JsonResult.ok(favoriteSightVOS);
    }

    /**
     * 删除景点收藏
     */
    @GetMapping("/{sightId:[0-9]+}/sight/delete")
    @PreAuthorize("hasAuthority('/account/user/system')")
    @ApiOperation("删除景点收藏")
    @ApiOperationSupport(order = 550)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sightId", value = "景点ID", required = true, dataType = "long")
    })
    public JsonResult deleteFavoriteSight(@PathVariable @Range(min = 1, message = "请提交合法的景点ID值！")Long sightId,
                                          @ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        favoriteService.deleteFavoriteSight(sightId,principal.getId());
        return JsonResult.ok();
    }

    /**
     * 添加商品收藏
     */
    @GetMapping("/{goodId:[0-9]+}/good/add")
    @PreAuthorize("hasAuthority('/account/user/system')")
    @ApiOperation("添加商品收藏")
    @ApiOperationSupport(order = 560)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodId", value = "商品ID", required = true, dataType = "long")
    })
    public JsonResult addFavoriteGood(@PathVariable @Range(min = 1, message = "请提交合法的商品ID值！")Long goodId,
                                      @ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        favoriteService.addFavoriteGood(goodId,principal.getId());
        return JsonResult.ok();
    }

    /**
     * 查询商品收藏(自己)
     */
    @GetMapping("/good/select")
    @PreAuthorize("hasAuthority('/account/user/system')")
    @ApiOperation("查询商品收藏")
    @ApiOperationSupport(order = 570)
    public JsonResult selectFavoriteGood(@ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        List<FavoriteGoodVO> favoriteGoodVOS = favoriteService.selectFavoriteGood(principal.getId());
        return JsonResult.ok(favoriteGoodVOS);
    }

    /**
     * 删除商品收藏
     */
    @GetMapping("/{goodId:[0-9]+}/good/delete")
    @PreAuthorize("hasAuthority('/account/user/system')")
    @ApiOperation("删除商品收藏")
    @ApiOperationSupport(order = 580)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodId", value = "商品ID", required = true, dataType = "long")
    })
    public JsonResult deleteFavoriteGood(@PathVariable @Range(min = 1, message = "请提交合法的商品ID值！")Long goodId,
                                         @ApiIgnore @AuthenticationPrincipal CurrentPrincipal principal){
        favoriteService.deleteFavoriteGood(goodId,principal.getId());
        return JsonResult.ok();
    }
}
